<extend name="Base:main" />
<block name="title">
<title>蔬菜外卖 - 配送时间管理</title>
</block>
<block name="main-content">
<div class="row">
	<div class="box col-md-12">
		<div class="box-inner">
			<div class="box-header well" data-original-title="">
				<h2>
					<i class="glyphicon glyphicon-user"></i>配送区域管理
				</h2>

				<div class="box-icon">
					<a href="#" class="btn btn-add btn-round btn-default"><i
						class="glyphicon glyphicon-plus"></i></a> <a href="#"
						class="btn btn-minimize btn-round btn-default"><i
						class="glyphicon glyphicon-chevron-up"></i></a> <a href="#"
						class="btn btn-close btn-round btn-default"><i
						class="glyphicon glyphicon-remove"></i></a>
				</div>
			</div>
			<div class="box-content">
				<div class="alert alert-info">对配送区域进行查看以及管理</div>
				<table
					class="table table-striped table-bordered bootstrap-datatable datatable responsive">
					<thead>
						<tr>
							<th>序号</th>
							<th>配送起始时间</th>
							<th>配送结束时间</th>
							<th>配送地区</th>
							<th>配送类型</th>
							<th>配送状态</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						<foreach name="list" item="v">
						<tr>
							<td><if condition="($_GET['p'] eq 0)">{++$i}<else />{++$i +
								($_GET['p']-1) * 17}</if></td>
							<td>{$v.stime}</td>
							<td>{$v.etime}</td>
							<td>{$v.area}</td>
							<if condition="$v['type'] eq 1">
							<td>今日配送</td>
							</if>
							<if condition="$v['type'] eq 2">
							<td>明日配送</td>
							</if>
							<td><if condition="$v['status'] eq 1"> <input
									data-no-uniform="true" type="checkbox" class="iphone-toggle"
									checked /> <else /> <input data-no-uniform="true"
									type="checkbox" class="iphone-toggle" /> </if></td>
							<td>
								<button class="btn btn-primary btn-xs"
									onclick="edit({$v['id']});" data-toggle="modal">
									<i class="glyphicon glyphicon-edit icon-white"></i>
								</button>
								<button class="btn btn-danger btn-xs" onclick="del({$v['id']});"
									data-toggle="modal">
									<i class="glyphicon glyphicon-trash icon-white"></i>
								</button>
							</td>
						</tr>
						</foreach>
					</tbody>
				</table>
			</div>
			<!-- end box-content -->
		</div>
		<!-- end box-inner -->
	</div>
	<!-- end box -->
</div>
<!-- end row --> <!-- 添加菜单弹出框 -->
<div class="modal fade" id="myAddModal" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width: 900px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">添加配送时间</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal style-form" method="get">
					<div class="form-group">
						<label class="col-sm-2 col-sm-2 control-label">配送类型：</label>
						<div class="col-sm-3">
							<select id="type" name="type" class="form-control">
								<option value="1" selected="selected">今日配送</option>
								<option value="2">明日配送</option>
							</select>
						</div>
						<div class="col-sm-1"></div>
						<label class="col-sm-2 col-sm-2 control-label">配送地区：</label>
						<div class="col-sm-3">
							<select id="area" name="area" class="form-control">
								<option value="曼哈顿">曼哈顿</option>
								<option value="南汇小区">南汇小区</option>
								<option value="水心汇">水心汇</option>
							</select>
						</div>
						<div class="col-sm-1"></div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 col-sm-2 control-label">配送开始时间：</label>
						<div class="col-sm-3">
							<input id="datetimepicker1" class="form-control" type="text">
						</div>
						<div class="col-sm-1"></div>
						<label class="col-sm-2 col-sm-2 control-label">配送结束时间：</label>
						<div class="col-sm-3">
							<input id="datetimepicker2" class="form-control" type="text">
						</div>
						<div class="col-sm-1"></div>
					</div>


				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				<button type="button" class="btn btn-danger">确定</button>
			</div>
		</div>
	</div>
</div>
<!-- 编辑菜单弹出框 -->
<div class="modal fade" id="myEditModal" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width: 900px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">修改配送时间</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal style-form" method="get">
					<div class="form-group">
						<label class="col-sm-2 col-sm-2 control-label">配送类型：</label>
						<div class="col-sm-3">
							<select id="etype" name="etype" class="form-control">
								<option value="1">今日配送</option>
								<option value="2">明日配送</option>
							</select>
						</div>
						<div class="col-sm-1"></div>
						<label class="col-sm-2 col-sm-2 control-label">配送地区：</label>
						<div class="col-sm-3">
							<select id="earea" name="earea" class="form-control">
								<option value="曼哈顿">曼哈顿</option>
								<option value="南汇小区">南汇小区</option>
								<option value="水心汇">水心汇</option>
							</select>
						</div>
						<div class="col-sm-1"></div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 col-sm-2 control-label">配送开始时间：</label>
						<div class="col-sm-3">
							<input id="edatetimepicker3" class="form-control" type="text">
						</div>
						<div class="col-sm-1"></div>
						<label class="col-sm-2 col-sm-2 control-label">配送结束时间：</label>
						<div class="col-sm-3">
							<input id="edatetimepicker4" class="form-control" type="text">
						</div>
						<div class="col-sm-1"></div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				<button type="button" class="btn btn-danger">确定</button>
			</div>
		</div>
	</div>
</div>

<!-- 删除菜单弹出框 -->
<div class="modal fade" id="myDelModal" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width: 900px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">删除配送时间</h4>
			</div>
			<div class="modal-body">
				<p id="sccontent" name="sccontent">你确定要删除吗？该操作不可恢复！</p>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				<button type="button" class="btn btn-danger">确定</button>
			</div>
		</div>
	</div>
</div>
</block>
<block name="js-content"> <script
	src="__PUBLIC__/assets/js/jquery-ui-1.9.2.custom.min.js"></script> <script
	src="__PUBLIC__/assets/js/jquery.tagsinput.js"></script> <script
	type="text/javascript" src="__PUBLIC__/js/jquery.datetimepicker.js"></script>
<script type="text/javascript"
	src="__PUBLIC__/assets/js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>
<script type="text/javascript">
  var delurl="__APP__/Admin/Order/delTime";
  var getInfo="__APP__/Admin/Order/getInfo";
  var editTimeurl="__APP__/Admin/Order/editDate";
  var addurl = "__APP__/Admin/Order/addDate";
  var changeStatusurl="__APP__/Admin/Order/changeStatus";
  //时间控件
	$('#datetimepicker1').datetimepicker({
		datepicker:false,
		format:'H:i',
		step:10
	});
	$('#datetimepicker2').datetimepicker({
		datepicker:false,
		format:'H:i',
		step:10
	});
  $('#edatetimepicker3').datetimepicker({
    datepicker:false,
    format:'H:i',
    step:10
  });
  $('#edatetimepicker4').datetimepicker({
    datepicker:false,
    format:'H:i',
    step:10
  });
  //打开添加的modal.
  function add(){
  	$("#myAddModal").modal('show');
  }
  function mclick(obj){
      var tid = $(obj).attr('tid');
      $.post(changeStatusurl,{tid:tid,status:0},
            function(data){
              if(data.state==1){
                 $(obj).children('.switch-animate').removeClass('switch-on').addClass('switch-off');
                 $(obj).attr('onclick','dclick(this);');
              }
            }
        );
  }
  function dclick(obj){
      var tid = $(obj).attr('tid');
      $.post(changeStatusurl,{tid:tid,status:1},
            function(data){
              if(data.state==1){
                 $(obj).children('.switch-animate').removeClass('switch-off').addClass('switch-on');
                 $(obj).attr('onclick','mclick(this);');
              }
            }
        );
    }
  //打开删除的modal.
  function  del(i)
  {
  	var id=i;
  	$(".btn-danger").attr('id',id);
  	$("#myDelModal").modal('show');
  }
  //打开编辑的modal.
  function  edit(i)
  {
  	var id=i;
  	$(".btn-danger").attr('id',id);
  	$.post(getInfo,{id:id},function(data){
  		$("#etype").val(data.type);
  		$("#earea").val(data.area);
  		$("#edatetimepicker3").val(data.stime);
  		$("#edatetimepicker4").val(data.etime);
  	});
  	$("#myEditModal").modal('show');
  }
//编辑框关闭时候的操作. 
  $("#myEditModal").on("hidden.bs.modal", function() {
		$(this).removeData("bs.modal");
	});


 //添加操作
	$('#myAddModal').on('click', 'button.btn-danger', function (a) {
				 var type = $("#type").val();
				 var area = $("#area").val();
				 var stime = $("#datetimepicker1").val();
				 var etime = $("#datetimepicker2").val();
				 $.post(addurl,{type:type,area:area,stime:stime,etime:etime},
					function(data){
						if(data.res=='1'){
							alert("添加成功！");
							setTimeout(function(){window.location.reload();},1000);
					   }else{
						    alert("添加失败！");
						    setTimeout(function(){window.location.reload();},1000);
						}	
					},
					'json'
				);
		});
//删除操作
	$('#myDelModal').on('click', 'button.btn-danger', function (a) {
			  var id=$(this).attr("id");
				 $.post(delurl,{id:id},
					function(data){
						if(data.res=='1'){
							$("#sccontent").html("删除成功！");
							setTimeout(function(){window.location.reload();},1000);
					   }else{
						  $("#sccontent").html(data.msg);
						}	
					},
					'json'
				);
		});
//编辑操作.
	$('#myEditModal').on('click','button.btn-danger',function (a){
				var id=$(this).attr("id");
		  		var type=$("#etype").val();
		  		var area=$("#earea").val();
		  		var stime=$("#edatetimepicker3").val();
		  		var etime=$("#edatetimepicker4").val();
          $.post(editTimeurl,{id:id,type:type,area:area,stime:stime,etime:etime},
            function(data){
              if(data.res=='1'){
                alert("修改成功！");
                setTimeout(function(){window.location.reload();},1000);
               }else{
                  alert("修改失败！");
                  setTimeout(function(){window.location.reload();},1000);
                } 
              },
              'json'
          );
 
		  	});
  </script> </block>
